package team.bailan.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import team.bailan.entity.domain.User;
import team.bailan.mapper.UserMapper;

import java.time.LocalDateTime;
import java.util.List;

@Configuration
@EnableScheduling
public class ScheduleTaskConfig {
    @Autowired
    private UserMapper userMapper;

    @Scheduled(cron = "0 0 0 * * ?")
    private void configureTasks() {
        System.out.println("执行静态定时任务时间: " + LocalDateTime.now());
        List<User> users = userMapper.selectList(null);
        System.out.println(users);
        for (User user : users) {
            user.setGivenCount(1);
            userMapper.updateById(user);
        }
    }
}
